<template>
    <div style="margin-left: 22px;" v-if="props.isCheck">
        <div class="lfCon1-item">
            <div class="hdTitle13">校验类型：</div>
            <el-select v-model="itemCheck1.dictSpeCheckType"
             @change="changeSpeCheckType" style="width: 280px" :disabled="props.isRead">
                <el-option v-for="(item, index) in props.options" :key="index" :label="item.name" :value="item.code" />
            </el-select>
        </div>
        <div class="lfCon1-item" style="margin-left: 75px;">
            <select-sim v-model="itemCheck1.forRiskBusinessId" :property="'forRiskBusinessId'" :disabled="props.isRead"
                :defaultList="[{ 
                    id: itemCheck1.forRiskBusinessId ? itemCheck1.forRiskBusinessId :'', 
                    name: itemCheck1.riskBusinessName || ''
                }]" @save="saveSim1" :placeholder="'请选择'" 
                style="width: 280px; "
                v-if="itemCheck1.dictSpeCheckType == '1'"/>
            <!-- <el-input style="width: 280px" placeholder="请输入" v-else-if="itemCheck1.dictSpeCheckType == '2'" v-model="itemCheck1.className" :disabled="props.isRead"
            @blur="changeClassName"></el-input> -->
            <div v-if="itemCheck1.dictSpeCheckType == '2'">
                <select-sim v-model="itemCheck1.className" :property="'turnAround'" :disabled="props.isRead"
                    :defaultList="[{ 
                        id: itemCheck1.className? itemCheck1.className :'', 
                        name: itemCheck1.className || ''
                    }]" @save="saveSim2" :placeholder="'请选择'" style="width: 280px; " v-if="props.pageSrc == 'edgeTurn'"
                />
                <!-- 启动校验 -->
                <select-sim v-model="itemCheck1.className" :property="'startCheck'" :disabled="props.isRead"
                    :defaultList="[{ 
                        id: itemCheck1.className? itemCheck1.className :'', 
                        name: itemCheck1.className || ''
                    }]" @save="saveSim2" :placeholder="'请选择'" style="width: 280px; " v-else-if="props.pageSrc == 'checkConfig'"
                />
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import selectSim from '@/components/remoteSelect/simple.vue';

interface CommonCheck {
    dictSpeCheckType: string;
    forRiskBusinessId: string;
    riskBusinessName: string;
    className: string;
}

const props = defineProps({
    isRead: {
        type: Boolean,
        default: false
    },
    isCheck: {
        type: Boolean,
        default: false
    },
    itemCheck: {
        type: Object as () => CommonCheck,
        default: () => ({
            dictSpeCheckType: '',
            forRiskBusinessId: '',
            riskBusinessName: '',
            className: '',
        })
    },
    options: {
        type: Array as () => any[],
        default: () => []
    },
    index: {
        type: Number,
        default: -1
    },
    pageSrc: {
        type: String,
        default: ''
    }
});

// 解构 props
const itemCheck1 = reactive<CommonCheck>({
    dictSpeCheckType: '',
    forRiskBusinessId: '',
    riskBusinessName: '',
    className: '',
});
const emit = defineEmits([ 'saveRiskBusiness', 'changeSpeCheckType','saveClassName']);
const saveSim1 = (msg: any) => {
    itemCheck1.forRiskBusinessId = msg.value?msg.value:null;
    itemCheck1.riskBusinessName = msg.item?msg.item.name:null;
    const param = {
        val: {
            id: itemCheck1.forRiskBusinessId,
            name: itemCheck1.riskBusinessName
        },
        index: props.index
    };
    emit('saveRiskBusiness', JSON.parse(JSON.stringify(param)));
}
const saveSim2 = (msg: any) => {
    itemCheck1.className = msg.value?msg.value:null;
    const param = {
        val: itemCheck1.className,
        index: props.index
    };
    emit('saveClassName',  JSON.parse(JSON.stringify(param)));
}

const changeSpeCheckType = (val: any) => {
    const param = {
        val: val,
        index: props.index
    };
    emit('changeSpeCheckType',  JSON.parse(JSON.stringify(param)));
    itemCheck1.forRiskBusinessId = '';
    itemCheck1.riskBusinessName = '';
    itemCheck1.className = '';
};
watch(
    () => props.itemCheck,
    (newValue) => {
        Object.assign(itemCheck1, JSON.parse(JSON.stringify(newValue)));
    }
);
onMounted(() => {
    if (props.itemCheck) {
        Object.assign(itemCheck1, JSON.parse(JSON.stringify(props.itemCheck)));
    }
});
</script>

<style scoped lang="scss">
/* 添加必要的样式 */
</style>